/**
 * 初始化订单管理详情对话框
 */
var TOrderInfoDlg = {
    tOrderInfoData: {}
};

function CloseWebPage() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
            window.opener = null;
            window.close();
        } else {
            window.open('', '_top');
            window.top.close();
        }
    }
    else if (navigator.userAgent.indexOf("Firefox") > 0) {
        window.location.href = 'about:blank ';
    } else {
        window.opener = null;
        window.open('', '_self', '');
        window.close();
    }
}

/**
 * 关闭此对话框
 */
TOrderInfoDlg.close = function () {
    CloseWebPage();
}

/**
 * 提交添加
 */
TOrderInfoDlg.addSubmit = function () {

    jqPrint();

}

function jqPrint() {
    $("#myPrintArea").print({
        globalStyles: true,
        mediaPrint: true,
        stylesheet: null,
        noPrintSelector: ".no-print",
        iframe: false,
        append: null,
        prepend: null,
        manuallyCopyFormValues: true,
        deferred: $.Deferred()
    });
}
function addSumRow(res, curr, count){
    var result=0;
    //如果是异步请求数据方式，res即为你接口返回的信息。
    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
    var pieces=0,hj=0,zz=0,sh=0,ty=0;
    var xjhj=0,yjhj=0;//现结合计,月结合计
    for(var i=0;i<res.data.length;i++){
        result+=(parseFloat(res.data[i].payment)+parseFloat(res.data[i].collection)+parseFloat(res.data[i].zz)*(-1)+parseFloat(res.data[i].sh)*(-1)+parseFloat(res.data[i].ty)*(-1)+parseFloat(res.data[i].extra_money));
        if(!isNaN(res.data[i].goods_piece)){
            pieces+=res.data[i].goods_piece;
        }
            hj+=(parseFloat(res.data[i].payment)+parseFloat(res.data[i].collection)+parseFloat(res.data[i].extra_money))
        if(!isNaN(res.data[i].zz)){
            zz+=res.data[i].zz;
        }
        if(!isNaN(res.data[i].sh)){
            sh+=res.data[i].sh;
        }
        if(!isNaN(res.data[i].ty)){
            ty+=res.data[i].ty;
        }
        xjhj=xjhj.add(res.data[i].xj);
        yjhj=yjhj.add(res.data[i].yj);
    }
var tr='<tr data-index='+count+' class="">'+
        '<td colspan="5" align="center" style=" " >合计</td>'+
        '<td data-field="goods_piece"><div class="layui-table-cell laytable-cell-1-goods_piece">'+pieces+'</div></td>'+
        '<td data-field="mode" data-content="1"><div class="layui-table-cell laytable-cell-1-mode"></div></td>'+
        '<td data-field="hj" data-content=""><div class="layui-table-cell laytable-cell-1-hj">'+hj+'</div></td>'+
        '<td data-field="zz"><div class="layui-table-cell laytable-cell-1-zz">'+zz+'</div></td>'+
        // '<td data-field="sh"><div class="layui-table-cell laytable-cell-1-sh">'+sh+'</div></td>'+
        // '<td data-field="ty"><div class="layui-table-cell laytable-cell-1-ty">'+ty+'</div></td>'+
        '<td data-field="receipt"><div class="layui-table-cell laytable-cell-1-receipt"></div></td>'+
    '</tr>';
    $("table tbody").append(tr);
    $('#ys_money').html(result);
    $('#yj_money').html(yjhj);
    $('#xj_money').html(xjhj);
}
var table=null;
$(function () {

    layui.use('table', function () {
       table = layui.table;
        table.render({
            elem: '#PPtable',
            id:'TorderPrint'
            , url: Feng.ctxPath + "/tOrder/tDataList?ids=" + $('#ids').val()
            ,skin: 'row'
            ,size: 'sm',
            page: false
            , cols: [[
                {field: 'original_num', width: 100, title: '单号' }
                , {field: 'consignee', width: 120, title: '收货人'}
                , {field: 'receiving_phone', width:125, title: '收货人电话'}
                , {field: 'receivingAddress', width: 125, title: '送货地址' }
                , {field: 'goods_name', width: 100, title: '货物名称' }
                , {field: 'goods_piece', width: 54, title: '件数'}
                , {field: 'mode', width: 78, title: '配送方式'
                    ,templet: function (d) {
                   if(d.mode==0){
                        return "自提";
                   }else  if(d.mode==1){
                        return "配送";
                   }
                }}
                , {field: 'hj', width: 80, title: '合计收款',
                    templet: function (d) {
                        return parseFloat(d.payment)+parseFloat(d.collection)+parseFloat(d.extra_money);
                    }
                }
                , {field: 'zz', width: 66, title: '中转费' }
                // , {field: 'sh', width: 66, title: '送货费' }
                // , {field: 'ty', width: 66, title: '搬运费' }
                , {field: 'notice', width: 78, title: '等通知发货',   templet: function (d) {
                    if(d.notice==1){
                        return "是";
                    }else {
                        return "";
                    }
                } }
                , {field: 'receipt', width: 78, title: '回单要求' }
            ]],
            done: function (res, curr, count) {
                addSumRow(res, curr, count);//添加总计行
            }
        });
    });


});
